<?php
class Admin_Form_Newscat extends Zend_Form
{
    public function init()
    {
        $this->setName("admin");

        $newsCatId = new Zend_Form_Element_Hidden('id');
        $newsCatId->addFilter('Int');
        $newsCatId->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
        
        $catName = new Zend_Form_Element_Text('name');
        $catName->setLabel('Tên danh mục *')->setRequired(true)->addValidator('NotEmpty')->addFilter('StripTags')->addFilter('StringTrim');
        $catName->setAttrib('class','span12')->setAttrib('placeholder','Tên danh mục');
        $catName->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');                                
        
        $parent = new Zend_Form_Element_Select('parent');
        $parent->addFilter('Int');         
        $parent->setLabel('Danh mục cha')->setAttrib('class','span6');                
        $parent->addMultiOption(null,'--- None ---');
        $modelNewsCat = new Admin_Model_Newscat();
        $catList = $modelNewsCat->getFirstLevel();                                 
        foreach($catList as $cat) {
            $parent->addMultiOption($cat['id'],$cat['name']);
        }
        $parent->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
        
        $ord = new Zend_Form_Element_Text('ord');
        $ord->setLabel('Thứ tự')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('Int');
        $ord->setValue('1')->setAttrib('class','span6');
        $ord->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');                
        
        $display = new Zend_Form_Element_Checkbox('display');
        $display->setLabel('Hiển thị');                        
        $display->setAttrib('class','checkbox')->setAttrib('checked','checked');
        $display->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
        
        $keywords = new Zend_Form_Element_Text('keywords');
        $keywords->setLabel('Meta Keywords')->addFilter('StripTags')->addFilter('StringTrim');
        $keywords->setAttrib('class','span12');
        $keywords->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');

        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel('Meta Description')->addFilter('StripTags')->addFilter('StringTrim');
        $description->setAttrib('rows','6')->setAttrib('class','span12');
        $description->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
        
        $url = new Zend_Form_Element_Text('seourl');
        $url->setLabel('Seo Url *')->addFilter('StripTags')->addFilter('StringTrim');
        $url->setAttrib('class','span6');
        $url->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
                
        // Control Button
        $submit = new Zend_Form_Element_Submit('submit');        
        $submit->setLabel('Submit & Validate');
        $submit->setAttrib('class','btn btn-blue');
        $submit->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
                
        $reset = new Zend_Form_Element_Reset('reset');        
        $reset->setLabel('Reset');
        $reset->setAttrib('class','btn btn-yellow');
        $reset->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
                   
        $this->setDecorators(array(
                           array('viewScript',
                           array('viewScript'=>'template/form_newscat.phtml'),
                    )));          
                
        // add elements to form
        $this->addElements(array (
            $newsCatId, $catName, $parent, $ord, $display, $keywords, $description, $url, $submit, $reset
        ));
    }
}

